package com.shihb.utils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/4/22 9:02
 */
public class ProxyInvocationHandle  implements InvocationHandler {
  private Object target;

  public ProxyInvocationHandle setTarget(Object target) {
    this.target = target;
    return this;
  }
  public Object getProxy(){

    return  Proxy.newProxyInstance(
        this.getClass().getClassLoader(),
        this.target.getClass().getInterfaces(),
        this);
  }
  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object invoke = method.invoke(this.target, args);
    System.out.println("动态代理");
    return invoke;
  }
}
